<?php
/**
 * @author Nemo <nemo.xiaolan@gmail.com>
 */

!defined("IN_APP") && exit();

header("Content-Type:text/html;charset=utf-8");
unset($GLOBALS);

/**
 * 开启输出缓冲
 */
require "lib/func.ob.php";
//ob_start("ob_gzip");
ob_start();

/**
 * 全局约定配置
 */
$C = require "#@.php";

/**
 * Common Functions
 */
require "lib/func.common.php";

/**
 * 模板配置开始 初始化模板引擎
 */
require "vendor/smarty/Smarty.class.php";
$tpl = new Smarty();
foreach($C['tpl'] as $k=> $cnf) {
        $tpl->$k = $cnf;
}
unset($k);
unset($cnf);
$tpl->assign("C", $C);
/**
 * 初始化插件
 */
require "lib/class.pluggable.php";
Pluggable::init();

/**
 * 注册结束时的函数
 */
require "lib/func.when_shutdown.php";

/**
 * URI解析/分发
 */
require "lib/class.dispatcher.php";
Dispatcher::$type = $C["base"]["url_type"];
$action = Dispatcher::work();
$action["group"] = $action["group"] ? $action["group"] : "home";
$action["name"] = $action["name"] ? $action["name"] : "index";
$action_file = PROJECT_DIR.DS."actions".DS.$action["group"].DS.$action["name"].".php";

if(!is_file($action_file)) {
    $action["name"] = "index";
    $action_file = PROJECT_DIR.DS."actions".DS.$action["group"].DS.$action["name"].".php";
    if(!is_file($action_file)) {
        r("error/404");exit;
    }
}

$C["action"] = $action;

session_start();

require "lib/database/pdo.php";
require "lib/class.model.php";
require "actions/account/class.user.php";
require "actions/blog/func.blog.php";
require "actions/account/func.account.php";

$user = new User();
$tpl->assign("user", $user);

require $action_file;